package com.huping.config;

import com.alibaba.fastjson.serializer.ObjectSerializer;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.huping.interceptor.LoginCheckInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.time.LocalDateTime;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginCheckInterceptor loginCheckInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginCheckInterceptor).addPathPatterns("/api/**").excludePathPatterns("/api/basic/*","/api/hello");
    }

    @Bean
    public SerializeConfig serializeConfig() {
        SerializeConfig config = new SerializeConfig();
        // 对LocalDateTime类型指定自定义的序列化器
        config.put(LocalDateTime.class, objectSerializer());
        return config;
    }

    @Bean
    public ObjectSerializer objectSerializer() {
        return new FastjsonSerializer();
    }
}
